//
//  UITextField+UI.m
//  Demo1222
//
//  Created by ZhouZhenFu on 16/1/6.
//  Copyright © 2016年 HzB. All rights reserved.
//

#import "UITextField+UI.h"

@implementation UITextField (UI)

- (instancetype)initLoginTypeWithY:(CGFloat)y placeholder:(NSString *)placeholder leftImageName:(NSString *)leftImageName{
    
    if (self = [super init]) {
        //float x = kSpaceX;
        float x = 26.0;
        float width = kMainWidth - 2*x;
        //        float height = [image InProportionAtWidth:width];
        CGFloat height = 40.0;
        self.frame = CGRectMake(x, y, width, height);
        self.placeholder = placeholder;
        self.textColor = [UIColor blackColor];
        //        self.background = image;
        CGFloat fontsize = 17.0;
        self.font = [UIFont systemFontOfSize:fontsize];
        [self setPlaceholderFont:[UIFont systemFontOfSize:fontsize]];
        [self setPlaceholderColor:FONT_COLOR_BREAK];
        self.borderStyle = UITextBorderStyleNone;
        self.borderStyle = UITextBorderStyleNone;
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.autocorrectionType = UITextAutocorrectionTypeNo;

////        UIImage *image = [UIImage imageFileNamed:@"login_input"];
//        float x = kSpaceX;
//        float width = kMainWidth - 2*x;
////        float height = [image InProportionAtWidth:width];
//        CGFloat height = 40.0;
//        self.frame = CGRectMake(x, y, width, height);
//        self.placeholder = placeholder;
//        self.textColor = [UIColor blackColor];
////        self.background = image;
//        [self setType];
        [self setLeftViewAtImageName:leftImageName];
      }
    return self;
}
- (void)setType{

    CGFloat fontsize = 15.0;
    self.font = [UIFont systemFontOfSize:fontsize];
    [self setPlaceholderFont:[UIFont systemFontOfSize:fontsize]];
    [self setPlaceholderColor:FONT_COLOR_GRAY];
    self.borderStyle = UITextBorderStyleNone;
    self.borderStyle = UITextBorderStyleNone;
    self.autocapitalizationType = UITextAutocapitalizationTypeNone;
    self.autocorrectionType = UITextAutocorrectionTypeNo;
//    self.layer.cornerRadius= 8.0f;
    self.layer.masksToBounds=YES;
    self.layer.borderColor=[[UIColor blackColor]CGColor];
    self.layer.borderWidth= 1.0f;


}


- (instancetype)initLeftLabelTypeWithY:(CGFloat)y placeholder:(NSString *)placeholder leftLabelText:(NSString *)labelText{
    if (self = [super init]) {
        float x = kSpaceX;
        float width = kMainWidth - 2*x;
        //        float height = [image InProportionAtWidth:width];
        CGFloat height = 50.0;
        self.frame = CGRectMake(x, y, width, height);
        self.placeholder = placeholder;
        self.textColor = [UIColor blackColor];
        //        self.background = image;
        CGFloat fontsize = AUTO_MATE_WIDTH(15.0);
        self.font = [UIFont systemFontOfSize:fontsize];
        [self setPlaceholderFont:[UIFont systemFontOfSize:fontsize]];
        [self setPlaceholderColor:FONT_COLOR_GRAY];
        self.borderStyle = UITextBorderStyleNone;
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.autocorrectionType = UITextAutocorrectionTypeNo;
        self.leftViewMode = UITextFieldViewModeAlways;
        
        width = 80.0;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(kSpaceX, 0, width-kSpaceX, height-2)];
        label.text = labelText;
        label.font = [UIFont systemFontOfSize:15];
        [view addSubview:label];
        self.leftView = view;
        
    }
    
    return self;
}


- (instancetype)initReginTypeWithY:(CGFloat)y placeholder:(NSString *)placeholder leftImageName:(NSString *)leftImageName{
    if (self = [super init]) {
        
        float x = kSpaceX;
        float width = kMainWidth - 2*x;
        float height = 40.0;
        self.frame = CGRectMake(x, y, width, height);
        self.placeholder = placeholder;
        self.backgroundColor = [UIColor whiteColor];
        self.textColor = [UIColor blackColor];
        [self setType];
        [self setLeftViewAtImageName:leftImageName];
    }
    return self;
}


- (instancetype)initNormalTypeWithY:(CGFloat)y placeholder:(NSString *)placeholder
{
    if (self = [super init]) {
        float x = kSpaceX;
        float width = kMainWidth - 2*x;
        float height = AUTO_MATE_HEIGHT(40.0);
        self.frame = CGRectMake(x, y, width, height);
        self.placeholder = placeholder;
        self.backgroundColor = [UIColor whiteColor];
        self.textColor = kGrayColor;
        CGFloat fontsize = AUTO_MATE_WIDTH(14.0);
        self.font = [UIFont systemFontOfSize:fontsize];
        [self setPlaceholderFont:[UIFont systemFontOfSize:fontsize]];
        [self setPlaceholderColor:FONT_COLOR_GRAY];
        //self.layer.cornerRadius= 8.0f;
        self.borderStyle = UITextBorderStyleRoundedRect;
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.autocorrectionType = UITextAutocorrectionTypeNo;
        self.layer.masksToBounds = YES;
        [self addLeftSpace:kSpaceX];
    }
    return self;
}

- (instancetype)initMainWidthLabelTypeWithY:(CGFloat)y placeholder:(NSString *)placeholder leftLabelText:(NSString *)labelText
{
    if (self = [super init]) {
        float x = 0;
        float width = kMainWidth;
        //        float height = [image InProportionAtWidth:width];
        CGFloat height = 50.0;
        self.frame = CGRectMake(x, y, width, height);
        self.placeholder = placeholder;
        self.textColor = FONT_COLOR_GRAY;
        self.backgroundColor = [UIColor whiteColor];
        self.textAlignment = NSTextAlignmentRight;
        //        self.background = image;
        CGFloat fontsize = AUTO_MATE_WIDTH(15.0);
        self.font = [UIFont systemFontOfSize:fontsize];
        [self setPlaceholderFont:[UIFont systemFontOfSize:fontsize]];
        [self setPlaceholderColor:FONT_COLOR_GRAY];
        self.borderStyle = UITextBorderStyleNone;
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.autocorrectionType = UITextAutocorrectionTypeNo;
        self.leftViewMode = UITextFieldViewModeAlways;
        self.rightViewMode = UITextFieldViewModeAlways;
        
        width = 100.0;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, width-15, height-2)];
        label.text = labelText;
        label.font = [UIFont systemFontOfSize:15];
        [view addSubview:label];
        self.leftView = view;
        
        UIView *rightView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSpaceX, height)];
        self.rightView = rightView;
    }
    
    return self;
}


@end
